/**
 * @Author ZhangCuirong
 * @Date 2025/8/12 11:37
 * @description:
 */
public class Solution209 {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int sum = 0;
        int minLen = Integer.MAX_VALUE;
        for (int right = 0; right < nums.length; right++) {
            sum += nums[right];
            while (sum >= target) {
                minLen = Math.min(minLen, right - left + 1);
                sum -= nums[left++];
                if (sum >= target) {
                    minLen = Math.min(minLen, right - left + 1);
                }
            }
        }
        return minLen == Integer.MAX_VALUE ? 0 : minLen;
    }

    public static void main(String[] args) {
        Solution209 solution = new Solution209();
        int[] nums = new int[]{2, 3, 1, 2, 4, 3};
        int target = 7;
        int res = solution.minSubArrayLen(target, nums);
        System.out.println(res);
    }
}
